package com.workcell.workdata.xthings.controller;

import cn.hutool.core.util.ObjectUtil;
import com.workcell.workdata.common.core.util.R;
import com.workcell.workdata.common.security.annotation.Inner;
import com.workcell.workdata.xthings.dto.DataBaseAndRealTimeVo;
import com.workcell.workdata.xthings.service.CodeChainnumService;
import com.workcell.workdata.xthings.service.DataQrCodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author 廖博文
 * @Date 2022/12/5 15:09
 * @Description 数据二维码展示
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/dataQrCode" )
@Api(value = "dataQrCode", tags = "数据二维码展示")
public class DataQrCodeController {

	private final CodeChainnumService codeChainnumService;
	private final DataQrCodeService dataQrCodeService;

	/**
	 * 根据短链码获取二维码参数信息
	 * @param chainNum
	 * @return
	 */
	@ApiOperation(value = "根据短链码获取二维码参数信息", notes = "根据短链码获取二维码参数信息")
	@GetMapping("/getCodeInfoByChainNum")
	public R getCodeInfoByChainNum(String chainNum){
		return R.ok(codeChainnumService.getCodeInfoByChainNum(chainNum));
	}

	/**
	 * 获取设备的快照信息
	 * @param dataSnapshotInfoVo
	 * @return
	 */
	@ApiOperation(value = "获取设备的快照信息", notes = "获取设备的快照信息")
	@GetMapping("/getDataSnapshotInfo")
	public R getDataSnapshotInfo(@Validated DataBaseAndRealTimeVo.DataSnapshotInfoVo dataSnapshotInfoVo){
		return dataQrCodeService.getDataSnapshotInfo(dataSnapshotInfoVo.getCodeId(), dataSnapshotInfoVo.getHardwareType());
	}

	/**
	 * 获取设备的实时数据
	 * @param dataRealTimeInfoVo
	 * @return
	 */
	@ApiOperation(value = "获取设备的实时数据", notes = "获取设备的实时数据")
	@GetMapping("/getDataRealTimeInfo")
	public R getDataRealTimeInfo(@Validated DataBaseAndRealTimeVo.DataRealTimeInfoVo dataRealTimeInfoVo){
		return dataQrCodeService.getDataRealTimeInfo(dataRealTimeInfoVo.getDeviceNo(), dataRealTimeInfoVo.getHardwareType(),dataRealTimeInfoVo.getManufacturerCode());
	}

	/**
	 * 获取设备的最近六小时折线图数据
	 * @param dataHourLineChartVo
	 * @return
	 */
	@ApiOperation(value = "获取设备的最近六小时折线图数据", notes = "获取设备的最近六小时折线图数据")
	@GetMapping("/getDataHourLineChartInfo")
	public R getDataHourLineChartInfo(@Validated DataBaseAndRealTimeVo.DataHourLineChartVo dataHourLineChartVo){
		return dataQrCodeService.getDataHourLineChartInfo(dataHourLineChartVo.getDeviceNo(), dataHourLineChartVo.getHardwareType(),dataHourLineChartVo.getManufacturerCode());
	}

	@ApiOperation(value = "一物一码-获取设备的数据", notes = "一物一码-获取设备的数据")
	@GetMapping("/getHardwareDataToXOTOC")
	public R getHardwareDataToXOTOC(@Validated DataBaseAndRealTimeVo.DataXOTOCVo dataXOTOCVo){
		return dataQrCodeService.getHardwareDataToXOTOC(dataXOTOCVo.getDeviceNo(), dataXOTOCVo.getHardwareType(), dataXOTOCVo.getManufacturerCode());
	}

	@Inner
	@ApiOperation(value = "查询设备最新采集数据", notes = "查询设备最新采集数据")
	@GetMapping("/getHardwareBaseOpen")
	public R getRealData(String deviceNo, String hardwareType) {
		Object resultBean = dataQrCodeService.getRealData(deviceNo, hardwareType);
		if (ObjectUtil.isEmpty(resultBean)) {
			return R.failed("查询数据为空");
		}
		return R.ok(resultBean);
	}

}
